<template>
  <div class="eadd">
    <el-card class="box-card">
      <el-button
        class="submission priamry_border"
        style="display: flex;float: right"
        @click="back()"
        >返回</el-button
      >
      <div class="title">{{ roomid ? "编辑房型" : "添加房型" }}</div>
      <!-- 选择酒店 -->
      <div v-if="!this.$route.params.id">
        请选择酒店名称：
        <el-select
          v-model="roominfolist.jdId"
          placeholder="请选择酒店名称"
          @change="seletjd($event)"
        >
          <el-option
            v-for="item in options"
            :key="item.id"
            :label="item.jdName"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </div>
      <div style="margin: 15px 0"><hr /></div>
      <!-- 表单 -->
      <el-form
        ref="formValidate"
        class="frame"
        :inline="true"
        :rules="rules"
        :model="roominfolist"
        label-width="120px"
      >
        <el-form-item label="房间类型：" prop="storeName">
          <el-input
            v-model="roominfolist.fjType"
            maxlength="120"
            placeholder="请输入房间类型"
          />
        </el-form-item>
        <el-form-item label="饮品：" prop="storeName">
          <el-input
            v-model="roominfolist.drink"
            maxlength="120"
            placeholder="请输入饮品"
          />
        </el-form-item>
        <el-form-item label="房间设施：" prop="cateIds">
          <el-input
            v-model="roominfolist.facility"
            maxlength="120"
            placeholder="请输入房间设施"
          />
        </el-form-item>
        <el-form-item label="房间面积：" prop="storeName">
          <el-input
            v-model="roominfolist.fjArea"
            maxlength="120"
            placeholder="请输入房间面积"
          />
        </el-form-item>
        <el-form-item label="商品床型：" prop="cateIds">
          <el-input
            v-model="roominfolist.fjBedType"
            maxlength="120"
            placeholder="请输入床型"
          />
        </el-form-item>
        <el-form-item label="卫生间信息：" prop="storeName">
          <el-input
            v-model="roominfolist.fjToilet"
            maxlength="120"
            placeholder="请输入房间卫生间信息"
          />
        </el-form-item>
        <!-- <el-form-item label="房间类型：" prop="cateIds">
            <el-input
              v-model="roominfolist.fjType"
              maxlength="120"
              placeholder="请输入房间类型"
            />
          </el-form-item> -->
        <el-form-item label="房型名称：" prop="storeName">
          <el-input
            v-model="roominfolist.fxName"
            maxlength="120"
            placeholder="请输入房型名称"
          />
        </el-form-item>
        <el-form-item label="房间窗户信息：" prop="cateIds">
          <el-input
            v-model="roominfolist.fjWindows"
            maxlength="120"
            placeholder="请输入房间窗户信息"
          />
        </el-form-item>
        <el-form-item label="容纳人数：" prop="storeName">
          <el-input
            v-model="roominfolist.galleryful"
            maxlength="120"
            placeholder="请输入容纳人数"
          />
        </el-form-item>
        <el-form-item label="娱乐设备：" prop="storeName">
          <el-input
            v-model="roominfolist.recreation"
            maxlength="120"
            placeholder="请输入娱乐设备"
          />
        </el-form-item>
        <el-form-item label="洗漱用品：" prop="cateIds">
          <el-input
            v-model="roominfolist.wash"
            maxlength="120"
            placeholder="请输入洗漱用品"
          />
        </el-form-item>
        <span class="textarea">
          <el-form-item label="备注：" prop="cateIds">
            <span>
              <el-input
                type="textarea"
                v-model="roominfolist.remark"
                maxlength="240"
                placeholder="请输入备注"
              />
            </span>
          </el-form-item>
        </span>
        <!-- 室外景观（图片） -->
        <el-form-item label="室外景观：" prop="cateIds">
          <el-input
            v-model="roominfolist.outdoor"
            maxlength="120"
            placeholder="请输入室外景观（图片）"
          />
        </el-form-item>
        <!-- 是否可加房 -->
        <el-form-item label="是否可加床：" prop="cateIds">
          <el-radio v-model="roominfolist.fjBed" label="1">可以加</el-radio>
          <el-radio v-model="roominfolist.fjBed" label="0">不能加</el-radio>
        </el-form-item>
        <div style="margin-left:120px">
          <el-button type="primary" class="submission" @click="eadd(roomid)">{{
            roomid ? "编辑房型" : "添加房型"
          }}</el-button>
        </div>
      </el-form>
    </el-card>
  </div>
</template>
<script>
import {
  addRoominfoilApi,
  eidtRoominfoilApi,
  RoominfoDetailApi
} from "@/api/roomtypeInfo";
import { groggeryListApi } from "@/api/groggery";
export default {
  data() {
    return {
      //验证规则
      rules: {},
      //eadd数据源
      roominfolist: {
        createTime: "", //创建时间
        drink: "", //饮品
        facility: "", //房间设施
        fjArea: "", //房间面积
        fjBed: 0, //是否可以加床(1可以)
        fjBedType: "", //床型
        fjFloor: "", //楼层
        fjToilet: "", //房间卫生间信息
        fjType: "", //房间类型
        fjWindows: "", //房间窗户信息
        fxName: "", //房型名称
        galleryful: "", //容纳人数
        id: 0, //房间信息表id标识
        isDel: 0, //是否删除
        jdId: "", //酒店id
        outdoor: "", //室外景观（图片）
        recreation: "", //娱乐设备
        remark: "", //备注
        sort: "", //排序
        updateTime: "", //更新时间
        wash: "" //洗漱用品
      },
      //传过来的id
      roomid: "",
      pagesize: {
        // 每页数量
        limit: 20,
        // 页码
        page: 1
      },
      //查询所有酒店
      hotalForm: {
        limit: 10,
        page: 1
      },
      //选择酒店
      options: [],
      value: ""
    };
  },
  created() {
    this.gethotalList();
  },
  mounted() {
    if (this.$route.params.id) {
      this.roomid = this.$route.params.id;
      this.loadData(this.$route.params.id);
    }
  },
  methods: {
    //添加修改
    async eadd(roomid) {
      console.log("添加修改", roomid);
      // 修改
      if (roomid) {
        await eidtRoominfoilApi(this.roominfolist);
        this.$message.success("修改成功");
      } else {
        // 新增
        // const res = await roomListApi(this.pagesize);
        // this.roominfolist.jdId = res.list[0].jdId;
        await addRoominfoilApi(this.roominfolist);
        this.$message.success("新增成功");
      }
      this.$router.push("/amszs/roomInformation/index");
    },
    // 返回
    back() {
      this.$router.go(-1);
    },
    // 根据id查渲染
    async loadData(roomid) {
      const res = await RoominfoDetailApi({ id: roomid });
      console.log("res:", res);
      this.roominfolist = res;
    },
    // 获取所有的酒店
    async gethotalList() {
      const res = await groggeryListApi(this.hotalForm);
      this.options = res.list;
    },
    seletjd(id) {
      this.roominfolist.jdId = id;
    }
  }
};
</script>

<style lang="scss" scoped>
.eadd {
  padding: 20px;
  .textarea {
    .el-form-item :last-child {
      width: 600px;
    }
  }

  .title {
    font-weight: 700;
    font-size: 20px;
  }
  .frame {
    .el-form-item {
      .el-input {
        width: 600px;
      }
      .el-select {
        width: 70px;
      }
    }
  }
}
</style>
